package com.gpframework.module.controller.order;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.core.page.TableDataInfo;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.common.enums.YesNoEnum;
import com.gpframework.common.utils.poi.ExcelUtil;
import com.gpframework.module.order.domain.GpProductShelvesImg;
import com.gpframework.module.order.domain.req.GpProductShelvesImgAdd;
import com.gpframework.module.order.domain.req.GpProductShelvesImgReq;
import com.gpframework.module.order.domain.req.GpProductShelvesImgUpdate;
import com.gpframework.module.order.domain.vo.GpProductShelvesImgVo;
import com.gpframework.module.order.service.IGpProductShelvesImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
/**
 * @ClassName GpProductShelvesImgController
 * @Author gpframework
 * @Date 2023-09-11
 * @Version 1.0.0
 * @Description 货架图片信息Controller
 */
@Validated
@Api(tags = "货架图片信息")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/order/productShelvesImg" )
public class GpProductShelvesImgController extends BaseController {

    private final IGpProductShelvesImgService iGpProductShelvesImgService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2023-09-11
  * @Param gpProductShelvesImg
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('order:productShelvesImg:list')")
    @GetMapping("/list")
    public TableDataInfo<GpProductShelvesImgVo> list(GpProductShelvesImgReq gpProductShelvesImgReq)
    {
        startPage();
        QueryWrapper<GpProductShelvesImg> lqw = new QueryWrapper<GpProductShelvesImg>();
        gpProductShelvesImgReq.generatorQuery(lqw,true);
        List<GpProductShelvesImgVo> list = iGpProductShelvesImgService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2023-09-11
     * @Param gpProductShelvesImg
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('order:productShelvesImg:add')" )
    @Log(title = "添加货架图片信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpProductShelvesImgAdd gpProductShelvesImgAdd) {
        GpProductShelvesImg productShelvesImg = iGpProductShelvesImgService.getOne(new LambdaQueryWrapper<GpProductShelvesImg>()
                .eq(GpProductShelvesImg::getProductName, gpProductShelvesImgAdd.getProductName())
                .eq(GpProductShelvesImg::getColour, gpProductShelvesImgAdd.getColour())
                .eq(GpProductShelvesImg::getDelStatus, YesNoEnum.NO.getKey()));
        if (productShelvesImg != null) {
            return AjaxResult.error("该规格图片已录入，请勿重复录入");
        }
        GpProductShelvesImg gpProductShelvesImg = Convert.convert(new TypeReference<GpProductShelvesImg>() {}, gpProductShelvesImgAdd);
        return toAjax(iGpProductShelvesImgService.save(gpProductShelvesImg) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2023-09-11
     * @Param gpProductShelvesImg
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('order:productShelvesImg:edit')" )
    @Log(title = "修改货架图片信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpProductShelvesImgUpdate gpProductShelvesImgUpdate) {
        GpProductShelvesImg productShelvesImg = iGpProductShelvesImgService.getOne(new LambdaQueryWrapper<GpProductShelvesImg>()
                .eq(GpProductShelvesImg::getProductName, gpProductShelvesImgUpdate.getProductName())
                .eq(GpProductShelvesImg::getColour, gpProductShelvesImgUpdate.getColour())
                .eq(GpProductShelvesImg::getDelStatus, YesNoEnum.NO.getKey()));
        if (productShelvesImg != null && !Objects.equals(productShelvesImg.getId(), gpProductShelvesImgUpdate.getId())) {
            return AjaxResult.error("该规格图片已录入，请勿重复录入");
        }
        GpProductShelvesImg gpProductShelvesImg = Convert.convert(new TypeReference<GpProductShelvesImg>() {}, gpProductShelvesImgUpdate);
        return toAjax(iGpProductShelvesImgService.updateById(gpProductShelvesImg) ? 1 : 0);
    }


    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2023-09-11
     * @Param gpProductShelvesImg
     * @Return TableDataInfo
     */
    @ApiOperation("导出货架图片信息")
    @PreAuthorize("@ss.hasPermi('order:productShelvesImg:export')" )
    @Log(title = "导出货架图片信息" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(GpProductShelvesImgReq gpProductShelvesImgReq) {
        QueryWrapper<GpProductShelvesImg> lqw = new QueryWrapper<GpProductShelvesImg>();
        gpProductShelvesImgReq.generatorQuery(lqw,true);
        List<GpProductShelvesImgVo> list = iGpProductShelvesImgService.listVo(lqw);
        ExcelUtil<GpProductShelvesImgVo> util = new ExcelUtil<GpProductShelvesImgVo>(GpProductShelvesImgVo. class);
        return util.exportExcel(list, "productShelvesImg" );
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2023-09-11
     * @Param gpProductShelvesImg
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('order:productShelvesImg:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpProductShelvesImgVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpProductShelvesImgService.getVoById(id));
    }



    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2023-09-11
     * @Param gpProductShelvesImg
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('order:productShelvesImg:remove')" )
    @Log(title = "删除货架图片信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpProductShelvesImgService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
